﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class AddressTypeDataAccess
    {
        #region Methods
        public static AddressType BindDataToAddressType(DataRow row)
        {
            return CodeTableDataAccess.BindRowToCodeTable<AddressType>(row);
        }

        public static Guid Create(AddressType addressType)
        {
            Guid id = Guid.Empty;

            if(addressType != null)
            {
                id = CodeTableDataAccess.Create<AddressType>(StoredProcedures.USP_ADDRESSTYPECODE_CREATE, addressType.Description);            
            }

            return id;
        }

        public static void Delete(AddressType addressType)
        {
            Delete(addressType.ID);
        }

        public static void Delete(Guid id)
        {            
            List<Exception> exes = CodeTableDataAccess.Delete<AddressType>(StoredProcedures.USP_ADDRESSTYPECODE_DELETE, id);

            if(exes != null && exes.Count > 0)
            {
                throw exes[0];
            }
        }

        public static DataTable GetAll()
        {
            return CodeTableDataAccess.GetAll(StoredProcedures.USP_ADDRESSTYPECODE_GETALL);
        }

        public static DataRow GetByID(Guid id)
        {
            return CodeTableDataAccess.GetByID(StoredProcedures.USP_ADDRESSTYPECODE_GETBYID, id);
        }

        public static void Update(AddressType addressType)
        {
            if(addressType != null)
            {
                CodeTableDataAccess.Update<AddressType>(StoredProcedures.USP_ADDRESSTYPECODE_UPDATE, addressType.ID, addressType.Description);
            }
        }
        #endregion
    }
}